package com.Long.mqAck;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Title:
 * @Description:
 * @Author: guowl
 * @version： 1.0
 * @Date:2021/7/26
 * @Copyright: Copyright(c)2021 RedaFlight.com All Rights Reserved
 */
public class ConfirmConsumer {

    public static final String EXCHANAGE_NAME = "FANOUT_EXCHANAGE_ACK";
    public static final String USER_NAME = "admin";
    public static final String PASSWORD = "admin";
    public static final String HOST = "47.101.154.152";
    public static final int PORT = 5672;
    public static final String QUEUW_NAME1 = "queue3";
    public static final String QUEUW_NAME2 = "queue4";
    public static final String ROUTING_KEY = "ack.queue";

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(HOST);
        factory.setPort(PORT);
        factory.setUsername(USER_NAME);
        factory.setPassword(PASSWORD);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();//创建信道；
        channel.basicConsume(QUEUW_NAME1,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("consumer 消费了消息："+new String(body));
//                channel.basicAck(envelope.getDeliveryTag(),false);//告诉mq 消费了消息 消息确认机制（确认之后就会删除消息 顺序消费）
            }
        });



    }
}
